//
//  FQDLabVoteResultHeadCell.m
//  FakeQDaily
//
//  Created by mewxiv on 9/18/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDLabVoteResultHeadCell.h"
#import "FQDRestModel.h"
#import "UIImageView+WebCache.h"

#import "Masonry.h"

@interface FQDLabVoteResultHeadCell ()

@property (nonatomic, strong) UIImageView *contentImageView;
@property (nonatomic, strong) UIView *contentCoverView;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation FQDLabVoteResultHeadCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
        [self prepareConstraints];
    }
    return self;
}

- (void)prepareUI
{
    self.layer.masksToBounds = YES;
    _contentImageView = [[UIImageView alloc] init];
    _contentImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:_contentImageView];
    
    _contentCoverView = [[UIView alloc] init];
    _contentCoverView.backgroundColor = [UIColor blackColor];
    _contentCoverView.alpha = 0.6f;
    [_contentImageView addSubview:_contentCoverView];
    
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.font = FQDBoldFontWithSize(16.0f);
    _contentLabel.textColor = [UIColor whiteColor];
    _contentLabel.numberOfLines = 2;
    _contentLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_contentLabel];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = FQDRegularFontWithSize(14.0f);
    _titleLabel.textColor = [UIColor colorWithWhite:1.0f alpha:0.8f];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
}

- (void)prepareConstraints
{
    WeakSelf;
    [_contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.contentView);
    }];
    
    [_contentCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.contentImageView);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(20);
        make.right.lessThanOrEqualTo(weakSelf.contentView).offset(-28);
        make.bottom.equalTo(weakSelf.titleLabel.mas_top).offset(-5);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentLabel);
        make.right.lessThanOrEqualTo(weakSelf.contentView).offset(-34);
        make.bottom.equalTo(weakSelf.contentView).offset(-21);
    }];
}

- (void)setOption:(FQDLabOpinion *)option
{
    _option = option;
    
    NSURL *contentImageURL = [NSURL URLWithString:option.image];
    [self.contentImageView sd_setImageWithURL:contentImageURL];
    
    self.titleLabel.text = option.title;
    self.contentLabel.text = option.content;
}

+ (CGFloat)cellHeight
{
    return 170.0f;
}

+ (NSString *)reuseId
{
    return @"FQDLabVoteResultHeadCell";
}

@end
